package com.vodone.v1pin.video.delegate
{
	
	import com.vodone.v1pin.index.vo.PicVO;
	import com.vodone.v1pin.video.view.vo.MiaoshaVideoVO;
	import com.vodone.v1pin.video.view.vo.ProVO;
	import com.vodone.v1pin.video.view.vo.VideoConditionVO;
	import com.vodone.v1pin.video.view.vo.VideoVO;
	import com.vodone.v1pin.video.view.vo.WhuInfoVO;

	public class VideoConvertUtil
	{
		public static function getReplyPicList(obj:Object):Array
		{
			var temp:Array = [];
			var list:Array;
			var level:int = 0;
			if( obj.hasOwnProperty("data") )
			{
				list = obj["data"];
				var len:int = list.length;
				for( var i:int = 0 ; i < len ; i++ ){
					temp.push( getVideo( list[i] ) );
				}
			}
			
			return temp;
		}
		
		public static function getVideo( obj:Object ):VideoVO
		{
			var vo:VideoVO = new VideoVO();
			if( obj.hasOwnProperty("id") )
			{
				vo.autoid = obj["id"];
			}
			if( obj.hasOwnProperty("name") )
			{
				vo.VideoName = obj["name"];
			}
			if( obj.hasOwnProperty("url") )
			{
				vo.VideoUrl = obj["url"];
			}
			if( obj.hasOwnProperty("img") )
			{
				vo.VideoImg = obj["img"];
			}
			if( obj.hasOwnProperty("ProductCode") )
			{
				vo.ProductCode = obj["ProductCode"];
			}
			
			return vo;
		}
		
		public static function getPicList( obj:Object ):Array
		{
			var temp:Array = [];
			var list:Array;
			var level:int = 0;
			if( obj.hasOwnProperty("data") )
			{
				list = obj["data"];
				var len:int = list.length;
				for( var i:int = 0 ; i < len ; i++ ){
					temp.push( getPic( list[i] ) );
				}
			}
			
			return temp;
		}
		
		public static function getPic( obj:Object ):PicVO
		{
			var vo:PicVO = new PicVO();
			if( obj.hasOwnProperty("url") )
			{
				vo.url = obj["url"];
			}
			if( obj.hasOwnProperty("proid") )
			{
				vo.id = obj["procode"];
			}
			if( obj.hasOwnProperty("videourl") )
			{
				vo.videourl = obj["videourl"];
			}
			if( obj.hasOwnProperty("procode") )
			{
				vo.procode = obj["proid"];
			}
			
			return vo;
		}
		
		public static function getReplyConditionList(obj:Object,index:int = 1):Array
		{
			var list:Array;
			var temp:Array;
			if( obj.hasOwnProperty("data1") )
			{
				list = obj["data"+index];
				temp = new Array();
				var len:int = list.length;
				for( var i:int = 0 ; i < len ; i++ ){
					temp.push( getCondition( list[i] ) );
				}
			}
			
			return temp;
		}
		
		public static function getCondition( obj:Object ):VideoConditionVO
		{
			var vo:VideoConditionVO = new VideoConditionVO();
			if( obj.hasOwnProperty("id") )
			{
				vo.id = obj["id"];
			}
			if( obj.hasOwnProperty("name") )
			{
				vo.name = obj["name"];
			}
			
			return vo;
		}
		/**
		 * 获取秒杀的相关信息
		 * */
		public static function getMiaoShaVideoVO(obj:Object):MiaoshaVideoVO
		{
			var item:MiaoshaVideoVO = new MiaoshaVideoVO();
			if(null == obj)return item;
			if(obj is Array && (obj as Array).length > 0)
			{
				obj = obj[0];
			}
			if(obj.hasOwnProperty("id"))
			{
				item.id = obj["id"];
			}
			if(obj.hasOwnProperty("name"))
			{
				item.name = obj["name"];
			}
			if(obj.hasOwnProperty("url"))
			{
				item.url = obj["url"];
			}
			if(obj.hasOwnProperty("img"))
			{
				item.img = obj["img"];
			}
			if(obj.hasOwnProperty("Futime"))
			{
				item.Futime = int(obj["Futime"]) * 1000;
			}
			if(obj.hasOwnProperty("itemList"))
			{
				item.productList = getVideoProductList(obj["itemList"]);
			}
			if(obj.hasOwnProperty("IsDuse"))
			{
				item.IsDuse = obj["IsDuse"];
			}
			if(obj.hasOwnProperty("Bili"))
			{
				item.Bili = obj["Bili"];
			}
			if(obj.hasOwnProperty("Yanchi"))
			{
				item.Yanchi = int(obj["Yanchi"]) * 1000;
			}
			if(obj.hasOwnProperty("tagInfo"))
			{
				item.tagInfo = obj["tagInfo"];
			}
				
			return item;
		}
		public static function getVideoProductList(obj:Object):Array
		{
			var result:Array = [];
			var arr:Array = obj as Array;
			if(null == arr || arr.length == 0) return result;
			
			for(var i:int=0;i<arr.length;i++)
			{
				result.push( getProductImageVO(arr[i]) );
			}
			return result;
		}
		
		private static function getProductImageVO(obj:Object):ProVO
		{
			var item:ProVO = new ProVO();
			if(null == obj)return item;
			if(obj.hasOwnProperty("ProCode"))
			{
				item.ProCode = obj["ProCode"];
			}
			if(obj.hasOwnProperty("name"))
			{
				item.name = obj["name"];
			}
			if(obj.hasOwnProperty("v1Price"))
			{
				item.v1Price = obj["v1Price"];
			}
			if(obj.hasOwnProperty("mPrice"))
			{
				item.mPrice = obj["mPrice"];
			}
			if(obj.hasOwnProperty("discount"))
			{
				item.discount = obj["discount"];
			}	
			if(obj.hasOwnProperty("type"))
			{
				item.type = obj["type"];
			}
			if(obj.hasOwnProperty("beginTime"))
			{
				item.beginTime = int(obj["beginTime"]) * 1000;
			}
			if(obj.hasOwnProperty("endTime"))
			{
				item.endTime = int(obj["endTime"]) * 1000;
			}
			if(obj.hasOwnProperty("img"))
			{
				item.img = obj["img"];
			}
			return item;
		}
		/**
		 * 获取视频滚动显示的信息
		 * */
		public static function getWhuInfoList(obj:Object):Array
		{
			var result:Array = [];
			var arr:Array = obj as Array;
			if(null == arr || arr.length == 0) return result;
			
			for(var i:int = 0;i < arr.length ;i++)
			{
				result.push( getWhuInfoVO(arr[i]) );
			}
			return result;
		}
		private static function getWhuInfoVO(obj:Object):WhuInfoVO
		{
			var item:WhuInfoVO = new WhuInfoVO();
			if(null == obj) return item;
			
			if(obj.hasOwnProperty("id"))
			{
				item.id = obj["id"];
			}
			if(obj.hasOwnProperty("info"))
			{
				item.info = obj["info"];
			}
			if(obj.hasOwnProperty("time"))
			{
				item.time = obj["time"];
			}
			return item;
		}
			
		
	}
}